package com.example.kotlin.scrollingtable.java_type1;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.kotlin.scrollingtable.R;
import com.example.kotlin.scrollingtable.type1.model.Type1PriceModel;
import com.example.kotlin.scrollingtable.type1.model.Type1ProductModel;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class JavaType1Activity extends AppCompatActivity {

    private String TAG = JavaType1Activity.class.getName();
    private List mLeftDataList = new ArrayList();
    private List mRightDataList = new ArrayList();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_java_type1);
        JavaRvType1LeftAdapter mLeftAdapter = new JavaRvType1LeftAdapter();
        JavaRvType1RightAdapter mRightAdapter = new JavaRvType1RightAdapter();
        int produceIndex = 0;
        for (int i = 40; produceIndex <= i; ++produceIndex) {
           Type1ProductModel productModel = new Type1ProductModel();
            productModel.setProducrId(produceIndex);
            productModel.setProductName("股票名称" + produceIndex);
            int priceIndex = 0;

            for (int j = 4; priceIndex <= j; ++priceIndex) {
               Type1PriceModel mainPriceModel = new Type1PriceModel();
                mainPriceModel.setPriceName("股票" + produceIndex + "价格-" + priceIndex);
                mainPriceModel.setProductModel(productModel);
                this.mRightDataList.add(mainPriceModel);
            }
            this.mLeftDataList.add(productModel);
        }

        mLeftAdapter.setNewData(this.mLeftDataList);
        RecyclerView leftRecyclerView = this.findViewById(R.id.rv_list_left);
        leftRecyclerView.setAdapter(mLeftAdapter);

        mRightAdapter.setNewData(this.mRightDataList);
        leftRecyclerView = this.findViewById(R.id.rv_list_right);
        leftRecyclerView.setAdapter(mRightAdapter);

        mLeftAdapter.setRvMainRightAdapter(mRightAdapter);
        mRightAdapter.setRvRvMainLeftAdapter(mLeftAdapter);

        mLeftAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            public final void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Log.d(JavaType1Activity.this.TAG, "mLeftAdapter click position >> " + position);
            }
        });
        mRightAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            public final void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Log.d(JavaType1Activity.this.TAG, "mRightAdapter click position >> " + position);
            }
        });

        //TODO 注意喽，要划重点了，要考的
        //TODO 左侧的RecyclerView与右侧RecyclerView垂直方向的滑动相互监听，实现联动效果
        ((RecyclerView) this.findViewById(R.id.rv_list_left)).addOnScrollListener(new RecyclerView.OnScrollListener() {
            public void onScrolled(@NotNull RecyclerView recyclerView, int dx, int dy) {
                if (recyclerView.getScrollState() != RecyclerView.SCROLL_STATE_IDLE) {
                    JavaType1Activity.this.findViewById(R.id.rv_list_right).scrollBy(dx, dy);
                }

            }
        });
        ((RecyclerView) this.findViewById(R.id.rv_list_right)).addOnScrollListener(new RecyclerView.OnScrollListener() {
            public void onScrolled(@NotNull RecyclerView recyclerView, int dx, int dy) {
                if (recyclerView.getScrollState() != RecyclerView.SCROLL_STATE_IDLE) {
                    JavaType1Activity.this.findViewById(R.id.rv_list_left).scrollBy(dx, dy);
                }
            }
        });
    }
}
